package com.example.thread.executordemo.demo1;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ZhangLiang
 * @Date: 2021/07/09/10:34
 * @Description:这是一个简单的Runnable类，需要大约5秒钟来执行其任务。
 */
public class MyRunnable implements  Runnable{
    private String command;

    public MyRunnable(String command) {
        this.command = command;
    }

    @Override
    public void run() {
        System.out.println("当前线程名称: "+Thread.currentThread().getName()+" 开始时间 = "+ LocalDateTime.now());
        processCommand();
        System.out.println("当前线程名称: "+Thread.currentThread().getName()+" 结束时间 = "+ LocalDateTime.now());
    }

    private void processCommand() {
          try {
              Thread.sleep(5000);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
    }

    @Override
    public String toString() {
        return "MyRunnable{" +
                "command='" + command + '\'' +
                '}';
    }
}
